<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>无标题文档</title>



<script src="/js/vue.min.js"></script>

<script src="/elementui/index.js"></script>
<link href="/elementui/index.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="/js/axios.min.js"></script>
<link href="/css/layui.css" rel="stylesheet" type="text/css">  
<link href="/css/base.css" rel="stylesheet" type="text/css">  
</head>

<body style="margin: 13px;">
  <div id="loginDiv">
	<template>
		名称：<input type="text" v-model.trim="mingcheng" size="17"/>
		<input type="button" value="查询" @click="leibieRes()" class="lanse" style="width: 86px;"/>
	</template>
	<table class="layui-table">
    <thead>
      <tr>
		<th>序号</th>
        <th>名称</th>
        <th>简单介绍</th>
		<th>操作</th>
      </tr> 
    </thead>
    <tbody>
      <tr v-for="(leibie, index) in xianshilist" :key="leibie.id">
        <td>{{index+1}}</td>
        <td>{{leibie.mingcheng}}</td>
        <td>{{leibie.jieshao}}</td>
		<td>
			<input type="button" value="编辑" class="lvse" @click="edit(leibie)" style="width: 66px;"/>
			<input type="button" value="删除" class="hongse" @click="del(leibie.id)" style="width: 66px;"/>
	    </td>
      </tr>
    </tbody>
    </table>

	<el-pagination background 
		 layout="total, prev, pager, next" 
		 :total="total" 
		 :page-size="pageSize"
		 :current-page="currentPage" 
		 @current-change="handleCurrentChange">
	</el-pagination>
	

	<input type="button" value="添加分类" class="lanse" onclick="leibieAdd()" style="width: 99px;"/>

    <el-dialog title="编辑" :visible.sync="dialogFormVisible" width="60%">
	<table width="98%" align="center" border="0" cellpadding="4" cellspacing="1" bgcolor="#F5F5F5" style="margin-bottom:8px">
						
						<tr bgcolor="#FFFFFF" style="height: 38px;">
						    <td width="103" bgcolor="#FFFFFF" align="right">
						          名称：
						    </td>
						    <td bgcolor="#FFFFFF" align="left">
						        <input type="text" v-model="leibie.mingcheng" size="35"/>
						    </td>
						</tr>
						
						<tr bgcolor="#FFFFFF" style="height: 38px;">
						    <td width="103" bgcolor="#FFFFFF" align="right">
						          简单介绍：
						    </td>
						    <td bgcolor="#FFFFFF" align="left">
						        <input type="text" v-model="leibie.jieshao" size="45" />
						    </td>
						</tr>
						<tr bgcolor="#FFFFFF" style="height: 38px;">
						    <td width="103" bgcolor="#FFFFFF" align="right">
						        &nbsp;
						    </td>
						    <td bgcolor="#FFFFFF" align="left">
						       <input type="button" value="提交" @click="leibieUpdate" class="lanse" style="width: 86px;"/>&nbsp; 
						    </td>
						</tr>
	</table>
    </el-dialog>

  </div>
  


<script type="text/javascript">
    function leibieAdd()
	{
		var url="../leibie/leibieAdd.html";
		window.location.href=url;
	}

	var vm = new Vue({
		
		el: '#loginDiv',
		data: 
		{
			total:0,
			pageSize:2,
			currentPage:1,//当前页

			leibieList:[],
			xianshilist: null,	

			dialogFormVisible:false,
			leibie:{
				
			},

			/* 查询的 */
			mingcheng:"",
		},
		methods: 
		{
			getData()
			{
               axios({
						method: 'POST',
						url: '/leibieMana',
						params:{
							
						}
						}).then(data => {
							if (data.data.state == 66)
							{
								this.leibieList=data.data.data;
								this.total=this.leibieList.length;
								
	                            this.xianshilist = this.leibieList.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
							} 
						    
						}).catch(error => {
							alert(error);
			    })
			},
			
			handleCurrentChange(currentPage)//用户点的页码
			{
				var _this = this;
				if (_this.leibieList) 
				{
				   if (currentPage)
				   {
                      _this.currentPage = currentPage;
                   }
                   _this.xianshilist = _this.leibieList.slice((_this.currentPage - 1) * _this.pageSize,_this.currentPage * _this.pageSize);
                } else {}

			},

			
			edit(leibie)
			{
				this.leibie={...leibie};
				this.dialogFormVisible=true;
			},

			leibieUpdate()
			{
				axios({
						method: 'POST',
						url: '/leibieUpdate',
						data: this.leibie,
						/* params:{
							username:this.leibie.userName,
							password:this.leibie.userPw,
						} */
						}).then(data => {
							if (data.data.state == 66)
							{
								alert("修改成功");
								this.dialogFormVisible=false;
								this.getData();
							}  
						    
						}).catch(error => {
							alert(error);
						})
			},
			
			
			del(id)
			{
				if(confirm('您确定删除吗？'))
				{
					axios({
						method: 'POST',
						url: '/leibieDel',
						//data: this.leibie,
						params:{
							id:id,
						} 
						}).then(data => {
							if (data.data.state == 66)
							{
								alert("删除成功");
								this.currentPage=1;
								this.getData();
							}  
							
						}).catch(error => {
							alert(error);
					})
				}
			},

			leibieRes()
			{
				axios({
						method: 'POST',
						url: '/leibieRes',

						params:{
							mingcheng:this.mingcheng,
						}
						}).then(data => {
							if (data.data.state == 66)
							{
								this.leibieList=data.data.data;
								this.total=this.leibieList.length;
								
	                            this.xianshilist = this.leibieList.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
							} 
						    
						}).catch(error => {
							alert(error); 
					    
				})
				this.currentPage=1;
			}

		},
		created()
		{
            this.getData();
		}

	
	    
	})
</script>


<style>
    .el-pagination{
		text-align: right;
		padding-top: 20px;
	}
</style>

</body>
</html>
